//
//  YYTSubjectOneController.swift
//  DrivingLittleHelp
//
//  Created by rimi on 16/11/4.
//  Copyright © 2016年 rimi. All rights reserved.
//

import UIKit
import SnapKit
class YYTSubjectOneController: UIViewController {
    var bgView :UIView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        view.addSubview(bgView!)
    }
    func setupUI()  {
        let viewH:CGFloat = 120
        //左边的背景view
        let margin:CGFloat = 8.0
        bgView = UIView.init(frame: CGRect(x: 0, y: 64, width: SCREEN_WIDTH, height: 300))
        bgView?.isUserInteractionEnabled = true
        //左边图片
        let leftView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH/2, height: viewH))
        leftView.isUserInteractionEnabled = true
        bgView?.addSubview(leftView)
        let leftImage = UIImageView.init(frame: CGRect(x: SCREEN_WIDTH/4 - 20, y: margin, width: 40, height: 50))
        leftImage.backgroundColor = UIColor.gray
        leftView.addSubview(leftImage)
        //label
        let testL = UILabel()
        leftView.addSubview(testL)
        testL.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(leftImage.snp.bottom).offset(margin)
        }
        testL.text = "考题练习"
        testL.font = UIFont.systemFont(ofSize: 20)
        testL.textAlignment = .center
        let alltestL = UILabel()
        leftView.addSubview(alltestL)
        alltestL.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(testL.snp.bottom).offset(margin)
        }
        alltestL.textAlignment = .center
        alltestL.text = "共1377题"
        alltestL.font = UIFont.systemFont(ofSize: 13)
        alltestL.textColor = UIColor.gray
        let rightView = UIView.init(frame: CGRect(x: SCREEN_WIDTH/2, y: 0, width: SCREEN_WIDTH/2, height: viewH))
        rightView.isUserInteractionEnabled = true
        bgView?.addSubview(rightView)
        let rightImage = UIImageView.init(frame: CGRect(x: SCREEN_WIDTH/4 - 20, y: margin, width: 40, height: 50))
//        rightImage.image = UIImage(named: "")
        rightView.addSubview(rightImage)
        //label
        let righttestL = UILabel()
        rightView.addSubview(righttestL)
        righttestL.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(rightImage.snp.bottom)
        }
        righttestL.text = "模拟考试"
        righttestL.font = UIFont.systemFont(ofSize: 20)
        righttestL.textAlignment = .center
        let simulation = UILabel()
        rightView.addSubview(simulation)
        simulation.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(righttestL.snp.bottom)
        }
        simulation.textAlignment = .center
        simulation.text = "100%仿真"
        simulation.font = UIFont.systemFont(ofSize: 13)
        simulation.textColor = UIColor.gray
        let lineV = UIView.init(frame: CGRect(x: SCREEN_WIDTH/2 - 0.5, y: 0, width: 1, height: viewH))
        bgView?.addSubview(lineV)
        lineV.backgroundColor = UIColor.gray
        //添加手势
        let leftgesture = UITapGestureRecognizer.init(target: self, action: #selector(clickedLeftView))
        leftView.addGestureRecognizer(leftgesture)
        let rightGestrue = UITapGestureRecognizer.init(target: self, action: #selector(clickedRightView))
        rightView.addGestureRecognizer(rightGestrue)
        addBtn()
    }
    func addBtn()  {
        let titelArr = ["科一考规","答题技巧","我的错题","我的收藏"]
        let margin:CGFloat = 8.0
        let btnW:CGFloat = 70
        let btnH = btnW
        
        let interval:CGFloat = (SCREEN_WIDTH - 2 * margin - btnW * 4)/3
        for i in 0...3 {
            let index:CGFloat = CGFloat(i)
            let button = UIButton.init(frame: CGRect(x: margin + btnW * index + interval * index , y: 120, width: btnW, height: btnH))
//            button.backgroundColor = UIColor.blue
            button.setTitle(titelArr[i], for: .normal)
            button.setTitleColor(UIColor.black, for: .normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 13)
            bgView?.addSubview(button)
        }
    }
    func clickedLeftView()  {
        print("左边")
    }
    func clickedRightView()  {
        print("右边")
    }
}
